#ifndef __AutoLock_h
#define __AutoLock_h

#include "windows.h"

class CSimpleLock  
{
public:
    void UnLock()
    {LeaveCriticalSection(&m_critialSection);};
    void Lock()
    {EnterCriticalSection(&m_critialSection);};
    CSimpleLock()
    {InitializeCriticalSection(&m_critialSection);};
    virtual ~CSimpleLock()
    {DeleteCriticalSection(&m_critialSection);};
private:
    CRITICAL_SECTION m_critialSection;
};

class CAutoLock
{
public:
    CAutoLock(CSimpleLock& Lock)
        :m_Lock(Lock)
    {
        m_Lock.Lock();
    };
    ~CAutoLock()
    {
        m_Lock.UnLock();
    };
private:
    CSimpleLock& m_Lock;
};

#endif // __AutoLock_h
